package com.example.publishevent.controller;

import com.example.publishevent.entity.PlaceOrderEventMessage;
import com.example.publishevent.event.PlaceOrderEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 江黎
 * @since 2022-11-18
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @GetMapping
    public void placeOrder() {
        //消息
        PlaceOrderEventMessage eventMessage = new PlaceOrderEventMessage();
        //发布事件
        applicationEventPublisher.publishEvent(new PlaceOrderEvent(eventMessage));
    }
}
